<!doctype html>
<html lang="">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
    <style></style>
  </head>
  <body>
    <div id="app">
      <div><button @click="words+='~'">监听</button></div>
      <div><button @click="obj.words+='+'">深度监听</button></div>
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          words: '苹果',
          obj: {
            words: '苹果',
            age: 19,
          },
        },
        methods: {},
        computed: {},
        watch: {
          // 监听
          // 监听的属性值发生变化，就会触发对应的回调函数
          words(newValue, oldValue) {
            console.log('words', newValue, oldValue)
          },
          obj: {
            // 深度监听
            handler(newValue, oldValue) {
              console.log('obj', newValue, oldValue)
            },
            deep: true,
          },
        },
      })
    </script>
  </body>
</html>
